using DataLayer.Model.enums;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace DataLayer.Model
{
    [Table("Player")]
    public class Player : User
    {
        [Required]
        [MaxLength(255)]
        public string IDCode { get; set; }

        public string LanguageCode { get; set; }

        public DateTime BirthDate { get; set; }

        //Berg balace scale
        public int? BBS { get; set; }

        //Mini mental state examination
        public int? MMSE { get; set; }

        [MaxLength(255)]
        public string ThumbnailUrl { get; set; }

        [NotMapped]
        public StateTypes StateType
        {
            get
            {
                if (!BBS.HasValue) { return StateTypes.None; }

                else
                {
                    if (BBS > 0 && BBS < 38)
                        return StateTypes.Frail;

                    else if (BBS > 39 && BBS < 44)
                        return StateTypes.Transition;

                    else if (BBS > 45 && BBS < 55)
                        return StateTypes.Active;

                    else
                        return StateTypes.VeryActive;
                }
            }
        }

        [NotMapped]
        public bool RiskOfFalling
        {
            get
            {
                return this.BBS < 45;
            }
        }

        [NotMapped]
        public bool SupervisionRequired
        {
            get
            {
                return this.StateType == StateTypes.Frail || this.StateType == StateTypes.Transition;
            }
        }

        public virtual FitbitAccount FitbitAccount { get; set; }

        [Required]
        public virtual Professional Professional { get; set; }

        [Required]
        public virtual Administrator Administrator { get; set; }

        public virtual PlayerGroup PlayerGroup { get; set; }

        public virtual ICollection<IndoorExercisePersonal> IndoorExercisePersonals { get; set; }

        public virtual ICollection<OutdoorExerciseSocial_CheerMessage> OutdoorExerciseSocial_CheerMessage { get; set; }

        public virtual ICollection<SetTopBox> PlayerSetTopBoxes { get; set; }

        public virtual ICollection<OutdoorExercise> OutdoorExercises { get; set; }

        public Player()
        {
            this.IndoorExercisePersonals = new List<IndoorExercisePersonal>();
            this.OutdoorExerciseSocial_CheerMessage = new List<OutdoorExerciseSocial_CheerMessage>();
            this.PlayerSetTopBoxes = new List<SetTopBox>();
            this.OutdoorExercises = new List<OutdoorExercise>();
        }
    }
}
